package com.zyf.controller;

import com.zyf.common.result.Result;
import com.zyf.model.hosp.Hospital;
import com.zyf.service.HospitalService;
import com.zyf.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zyf
 * @date 2021年05月08日 17:52
 */
@Api("医院列表Controller")
@RestController
@RequestMapping("/admin/hosp/hospital")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @ApiOperation(value = "分页条件查询医院信息Api")
    @GetMapping("/list/{page}/{limit}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页"),
            @ApiImplicitParam(name = "limit", value = "每页显示条数，默认 10"),
            @ApiImplicitParam(name = "hospitalSetQueryVo", value = "条件查询实体类")
    })
    public Result listHosp(@PathVariable Integer page,
                           @PathVariable Integer limit,
                           HospitalQueryVo hospitalQueryVo
    ){
        Page<Hospital> pageModel = hospitalService.selectHospByPage(page,limit,hospitalQueryVo);
        return Result.ok(pageModel);
    }


    @ApiOperation(value = "更新医院上下线状态API")
    @PutMapping("/updateHospStatus/{id}/{status}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "医院id"),
            @ApiImplicitParam(name = "status", value = "医院的状态")
    })
    public Result updateHospStatus(@PathVariable String id,@PathVariable Integer status){
        boolean flag = hospitalService.updateHospStatus(id,status);
        if (flag){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    @ApiOperation(value = "查看医院的详情信息API")
    @GetMapping("/findHospById/{id}")
    @ApiImplicitParam(name = "id", value = "医院id")
    public Result findHospById(@PathVariable String id){
        Map<String,Object> hospital =  hospitalService.findHospById(id);
       return Result.ok(hospital);
    }
}
